﻿"""
Aura Graphics Engine.
"""
import pygame

class Animation:
    """
    Creates an animation.
    """
    def __init__(self,base_frame_name,attack_frames=None):
        self.loop=True
        self.n=0
        while self.loop:
            try:
                self.frame=Frame(base_frame_name+str(self.n+1)+".png")
                setattr(self,"frame%s"%self.n,self.frame)
                self.n+=1
            except:
                self.loop=False
        del self.loop,self.n,self.frame
        self.cur_frame=0
        self.output=None
        self.coordinates=[]
        if attack_frames:
            self.attack_frames=attack_frames

    def next_frame(self):
        self.output=getattr(self,"frame%s"%self.cur_frame)
        self.cur_frame+=1
        return self.output

class Button:
    """Creates a clickable button."""
    def __init__(self,image,coor):
        self.frame=Frame(image)
        self.image=self.frame.image
        self.rect=self.image.get_rect()
        self.x1,self.y1=coor[0],coor[1]
        self.x2,self.y2=self.x1+self.rect.width-1,self.y1+self.rect.height-1

    def click(self,x,y):
        """Checks if the mouse position passed is in the button's area. If so, returns true, else false."""
        if x>=self.x1 and x<=self.x2 and y>=self.y1 and y<=self.y2:
            return True
        else:
            return False

class Frame:
    """
    Creates an animation frame.
    """
    def __init__(self,image):
        self.image=load_image(image)
        #self.rect=self.image.get_rect()

def load_image(image,optimise=True):
    """
    Loads an image into memory.
    """
    image=pygame.image.load(image)
    if optimise:
        return image.convert()
    return image
